using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void newbutton_Click(object sender, EventArgs e)
    {
        if (AllFieldCustValidator.IsValid)
        {
            //List <BookBarter.Book> ListOfBooks = BookBarter.Book.
            
            //ListOfBooks

            Response.Redirect("~/SearchResults.aspx?txtISBN=" + txtISBN.Text + "&txtTitle=" + txtTitle.Text + "&txtAuthor="+txtAuthor.Text + "&txtSearchType="+txtSearchType.Value);
        }
    }
    protected void IsbnLengthValidator_ServerValidate(object source, ServerValidateEventArgs args)
    {
        //Check if all fields are empty
        if ((txtAuthor.Text == "") && (txtISBN.Text == "") && (txtTitle.Text == ""))
        {
            AllFieldCustValidator.ErrorMessage = "Please enter search criteria";
            args.IsValid = false;
        }
        //Check if there is data in txtISBN
        else if (txtISBN.Text != "")
        {
            //Check if the data is 10 digits long
            if (txtISBN.Text.Length != 10)
            {
                AllFieldCustValidator.ErrorMessage = "ISBN numbers are 10 digits";
                args.IsValid = false;
            }
            else
            {
                txtSearchType.Value = "I";
            }
        }
        //If the Author textbox is not empty and the Title box is empty, use the author search.
        else if ((txtAuthor.Text != "") && (txtTitle.Text == ""))
        {
            //Call Author Search
            txtSearchType.Value = "A";
        }
        else if ((txtTitle.Text != "") && (txtAuthor.Text == ""))
        {
            //Call Title Search
            txtSearchType.Value = "T";
        }
        else
        {
            //Call Title and Author Search
            txtSearchType.Value = "TA";
        }
    }
}
